﻿using System;
using System.Windows.Data;

namespace BizControl.Presentation.ActivityEditModule.Converters
{
  public class ParentOrPreviousActivityToActivityConverter : IMultiValueConverter
  {
    private readonly int HasParentIndex = 0;
    private readonly int HasPreviousIndex = 1;
    private readonly int ParentActivityIndex = 2;
    private readonly int PreviousActivityIndex = 3;

    #region IMultiValueConverter Members

    public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
      bool result = false;
      if (bool.TryParse(values[HasParentIndex].ToString(), out result) && result)
        return values[ParentActivityIndex];
      if (bool.TryParse(values[HasPreviousIndex].ToString(), out result) && result)
        return values[PreviousActivityIndex];
      return null;
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
    {
      return null;
    }

    #endregion
  }
}
